package com.bing.bingPro.controller.zd;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bing.bingPro.common.BaseResult;
import com.bing.bingPro.controller.dto.TZwMeteringVelocityDto;
import com.bing.bingPro.controller.vo.TBorderLatestNsDetailsVo;
import com.bing.bingPro.service.TBorderLatestNsDetailsService;
import com.bing.bingPro.util.ExcelData;
import com.bing.bingPro.util.WebExcelUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("tBrowderNsDetails")
public class TBrowderLustiestNsDetailsController {


    @Resource
    private TBorderLatestNsDetailsService tBorderLatestNsDetailsService;

    @PostMapping("list")
    public BaseResult<IPage<TBorderLatestNsDetailsVo>> tBrowderNsDetailsList(@RequestBody TZwMeteringVelocityDto tZwMeteringVelocityDto) {
        Assert.notBlank(tZwMeteringVelocityDto.getTime(), "not time");
        IPage<TBorderLatestNsDetailsVo> result = tBorderLatestNsDetailsService.tBrowderNsDetailsPageList(tZwMeteringVelocityDto);
        return new BaseResult<>(result);
    }


    @PostMapping("/export")
    public void tBrowderNsDetailsListExport(HttpServletResponse response, @RequestBody TZwMeteringVelocityDto tZwMeteringVelocityDto) {
        try {
            Assert.notBlank(tZwMeteringVelocityDto.getTime(), "not time");
            //查询数据
            List<TBorderLatestNsDetailsVo> result = tBorderLatestNsDetailsService.tBrowderNsDetailsList(tZwMeteringVelocityDto);
            //整理查询的数据
            List<ExcelData> excelDataList = new ArrayList<>();
            ExcelData excelData = new ExcelData(TBorderLatestNsDetailsVo.class,
                    result);
            excelDataList.add(excelData);
            //写出到浏览器
            WebExcelUtil.download(response, "测光测速空值及不规范详情" + tZwMeteringVelocityDto.getTime(), excelDataList);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
